/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view class="container">
		<block v-for="(item,index) in visit" :key="index">
			<view class="log_date">
				<view class="maleri30">{{item.date}}</view>
			</view>
			<block v-for="(visit_list_item,visit_index) in item.visit_list" >
				<view class="visit">
					<navigator class="goods_img" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id='+visit_list_item.goods_id" role="navigation">
						<image class="wh100" :src="hostUrl+'/mall/goods/thumb_image?goods_id='+visit_list_item.goods_id+'&width=400&height=400'" role="img"></image>
					</navigator>
					<view class="goods_detail">
						<navigator class="goods_name" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id='+visit_list_item.goods_id" role="navigation">{{visit_list_item.goods_name}}</navigator>
						<view class="goods_footer">
							<text class="price">
								￥{{visit_list_item.shop_price.toFixed(2)}}
							</text>
							<navigator class="similar" :url="'/pages/goods/goodsList/goodsList?cat_id='+visit_list_item.cat_id3" role="navigation">看相似</navigator>
							<view @tap="deleteVisit" class="del" :data-gidx="index" :data-vidx="visit_index">删除</view>
						</view>
					</view>
				</view>
			</block>
			
		</block>
		

	</view>
</template>

<script>
	import config from "@/api/config.js";
	import common from "@/common/common.js";
	import {getVisit,delateVisit} from "@/api/api.js";
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				visit:[],//访问日志
				loginInfo:"",
				hostUrl:config.host,//图片基础路径
				params:{
					p:1,//默认请求5条
				},
				total:""
			};
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onLoad(){
			if(this.hasLogin){
				this.getVisit(this.params)
			}else{
				common.islogin()
			}
		},
		onShow(){
			
		},
		methods:{
			/*访问日志*/ 
			getVisit(params){
				getVisit(params).then(res=>{
					if(res){
						this.visit=this.visit.concat(res.records);
						this.total=res.total
					}
					console.log(res)
				})
			},
			onReachBottom(){//下拉加载数据
			/*统计浏览记录的数量
			total:浏览记录的总条数
			*/
				var num=0;
				this.visit.forEach((i,index)=>{
					i.visit_list.forEach((j,ind)=>{
						num++
					})
				})
				if(num===this.total){
					console.log(num)
					common.toast("none","加载完了",2000)
					 return false;
				}
				this.params.p++;
				
				if(this.hasLogin){
					this.getVisit(this.params)
				}
			},
			delateVisit(params,gidx,vidx){
				delateVisit(params).then(res=>{
					if(res.status==1){
						this.visit[gidx].visit_list.splice(vidx,1)
						if(this.visit[gidx].visit_list.length==0){
							this.visit.splice(gidx,1)
						}
						
						common.toast('none','删除成功',3000)
					}
				})
			},
			
			/*删除*/ 
			deleteVisit(e){
				console.log(e)
				let gidx=e.currentTarget.dataset.gidx
				let vidx=e.currentTarget.dataset.vidx
				let goods_id=this.visit[gidx].visit_list[vidx].goods_id
				let params={
					goods_id:goods_id
				}
				this.delateVisit(params,gidx,vidx)
			},
		}
	}
</script>

<style lang="scss">
	.log_date {
		font-size: 28rpx;
		color: #666666;
		padding: 0rpx 28rpx;
		border-bottom: 1rpx solid #f3f3f3;
		margin-top: 20rpx;
	}

	.visit {
		background-color: #fff;
		font-size: 28rpx;
		padding: 10rpx 10rpx;
		width: 710rpx;
		border-radius: 10rpx;
		margin: 0 auto;
		margin-top: 10rpx;
		overflow: hidden;
		box-sizing: border-box;
	}

	.goods_img {
		width: 220rpx;
		height: 220rpx;
		border-radius: 5rpx;
		overflow: hidden;
		float: left;
	}

	.goods_detail {
		padding: 25rpx 0 0rpx 20rpx;
		width: 445rpx;
		float: left;
	}

	.goods_name {
		height: 64rpx;
		line-height: 32rpx;
		margin-bottom: 80rpx;
		overflow: hidden;
	}

	.goods_footer {
		height: 50rpx;
	}

	.price {
		color: red;
		float: left;
		margin-top: 6rpx;
	}

	.similar {
		width: 110rpx;
		height: 48rpx;
		line-height: 48rpx;
		text-align: center;
		margin-left: 20rpx;
		float: right;
		border-radius: 5rpx;
		background: #FF3B3B;
		color: #fff;
		font-size: 24rpx;
	}

	.del {
		width: 110rpx;
		height: 48rpx;
		line-height: 48rpx;
		text-align: center;
		margin-left: 20rpx;
		float: right;
		border-radius: 5rpx;
		background: #FFF;
		color: #999;
		font-size: 24rpx;
		border: 1px solid #E6E6E6;
	}
</style>
